// 路由鉴权:就是路由能不能被访问到权限设置->全局守卫完成
// 引入路由器
import router from './router';
// 引入用户相关仓库
import useUserStore from './store/modules/user';
// 引入大仓库
import pinia from '@/store';
let userStore = useUserStore(pinia);
// 存储用户未登录可以访问路由得路径
let whiteList = ["/home", '/hospital/register', '/hospital/detail', '/hospital/notice', '/hospital/close', '/hospital/search'];
// @ts-ignore
import nprogress from "nprogress";
nprogress.configure({ showSpinner: false });
// 添加相应的全局守卫
// 前置守卫
router.beforeEach((to, __, next) => {
    nprogress.start();
    // 判断用户是否登陆 -token
    let token = userStore.userInfo.token;
    if (token) {
        // 用户登陆
        next();
    } else {
        // 用户未登录
        if (whiteList.includes(to.path)) {
            next();
        } else {
            userStore.dialogVisible = true;
            next({
                path: '/home',
                query: {
                    redirext: to.fullPath
                }
            })
        }
    }
});

// 后置守卫
router.afterEach((to) => {
    document.title = '尚医通之小何很牛' + "-" + to.meta.title;
    nprogress.done();
});